{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-end">
        <button type="submit" form="form-geo-zone" formaction="{{ save }}" data-bs-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa-solid fa-floppy-disk"></i></button>
        <a href="{{ back }}" data-bs-toggle="tooltip" title="{{ button_back }}" class="btn btn-light"><i class="fa-solid fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    <div class="card">
      <div class="card-header"><i class="fa-solid fa-pencil"></i> {{ text_form }}</div>
      <div class="card-body">
        <form id="form-geo-zone" action="{{ save }}" method="post" data-oc-toggle="ajax">
          <div class="row mb-3">
            <label for="input-name" class="col-sm-2 col-form-label">{{ entry_name }}</label>
            <div class="col-sm-10">
              <input type="text" name="name" value="{{ name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control" required/>
              <div id="error-name" class="invalid-feedback"></div>
            </div>
          </div>
          <div class="row mb-3">
            <label for="input-description" class="col-sm-2 col-form-label">{{ entry_description }}</label>
            <div class="col-sm-10">
              <input type="text" name="description" value="{{ description }}" placeholder="{{ entry_description }}" id="input-description" class="form-control" required/>
              <div id="error-description" class="invalid-feedback"></div>
            </div>
          </div>
          <fieldset>
            <legend>{{ text_geo_zone }}</legend>
            <table id="zone-to-geo-zone" class="table table-bordered table-hover">
              <thead>
                <tr>
                  <th>{{ entry_country }}</th>
                  <th>{{ entry_zone }}</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                {% set zone_to_geo_zone_row = 0 %}
                {% for zone_to_geo_zone in zone_to_geo_zones %}
                  <tr id="zone-to-geo-zone-row-{{ zone_to_geo_zone_row }}">
                    <td><x-country name="zone_to_geo_zone[{{ zone_to_geo_zone_row }}][country_id]" value="{{ zone_to_geo_zone.country_id }}" id="x-country-{{ zone_to_geo_zone_row }}" input-id="input-country-{{ zone_to_geo_zone_row }}" input-class="form-select">
                        <option value="0">{{ text_select }}</option>
                      </x-country></td>
                    <td><x-zone name="zone_to_geo_zone[{{ zone_to_geo_zone_row }}][zone_id]" value="{{ zone_to_geo_zone.zone_id }}" target="x-country-{{ zone_to_geo_zone_row }}" input-id="input-zone-{{ zone_to_geo_zone_row }}" input-class="form-select">
                        <option value="0">{{ text_all_zones }}</option>
                      </x-zone></td>
                    <td class="text-end"><button type="button" onclick="$('#zone-to-geo-zone-row-{{ zone_to_geo_zone_row }}').remove();" data-bs-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa-solid fa-minus-circle"></i></button></td>
                  </tr>
                  {% set zone_to_geo_zone_row = zone_to_geo_zone_row + 1 %}
                {% endfor %}
              </tbody>
              <tfoot>
                <tr>
                  <td colspan="2"></td>
                  <td class="text-end"><button type="button" id="button-geo-zone" data-bs-toggle="tooltip" title="{{ button_geo_zone_add }}" class="btn btn-primary"><i class="fa-solid fa-plus-circle"></i></button></td>
                </tr>
              </tfoot>
            </table>
          </fieldset>
          <input type="hidden" name="geo_zone_id" value="{{ geo_zone_id }}" id="input-geo-zone-id"/>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
var zone_to_geo_zone_row = {{ zone_to_geo_zone_row }};

$('#button-geo-zone').on('click', function() {
    html = '<tr id="zone-to-geo-zone-row-' + zone_to_geo_zone_row + '">';
    html += '  <td><x-country name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][country_id]" value="{{ zone_to_geo_zone.country_id }}" id="x-country-' + zone_to_geo_zone_row + '" input-id="input-country-' + zone_to_geo_zone_row + '" input-class="form-select"><option value="0">{{ text_select }}</option></x-country></td>';
    html += '  <td><x-zone name="zone_to_geo_zone[' + zone_to_geo_zone_row + '][zone_id]" value="{{ zone_to_geo_zone.zone_id }}" target="x-country-' + zone_to_geo_zone_row + '" input-id="input-zone-' + zone_to_geo_zone_row + '" input-class="form-select" required><option value="0">{{ text_all_zones }}</option></x-zone></td>';
    html += '  <td class="text-end"><button type="button" onclick="$(\'#zone-to-geo-zone-row-' + zone_to_geo_zone_row + '\').remove();" data-bs-toggle="tooltip" title="{{ button_remove|escape('js') }}" class="btn btn-danger"><i class="fa-solid fa-minus-circle"></i></button></td>';
    html += '</tr>';

    $('#zone-to-geo-zone tbody').append(html);

    zone_to_geo_zone_row++;
});
//--></script>
{{ footer }}
